﻿using Hotel.Model;
using Hotle.BLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel_后端.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MemberController : ControllerBase
    {
        public MemberController(MemberBLL bll)
        {
            Bll = bll;
        }

        public MemberBLL Bll { get; }

        [HttpPost]
        /// <summary>
        /// 会员添加
        /// </summary>
        /// <returns></returns>
        public int MemberAdd(MemberModel member)
        {
            try
            {
                return Bll.MemberAdd(member);
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


        [HttpPost]
        /// <summary>
        /// 会员添加
        /// </summary>
        /// <returns></returns>
        public void WYMemberAdd(MemberModel model,string Phone, string Card)
        {
            try
            {
                var aa = Bll.WYMemberAdd(Phone, Card);
                if (aa == 1)
                {
                    var us = MemberAdd(model);
                    return;
                } 
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [HttpPost]
        /// <summary>
        /// 会员等级添加
        /// </summary>
        /// <returns></returns>
        public dynamic LevelAdd(LevelModel level)
        {
            try
            {
                //1.等级
                var aa = Bll.LevelAdd(level);
                return Ok(aa);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        public int LDelet(int id)
        {
            try
            {
                return Bll.LDelet(id);

            }
            catch (Exception ex)
            {

                throw;
            }
        }

        [HttpGet]
        /// <summary>
        /// 修改(反填-id查询)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MemberModel FanTianMember(int id)
        {
            try
            {
                return Bll.UpMember(id);
            }
            catch (Exception)
            {

                throw;
            }
        }

        [HttpPut]
        /// 修改 
        /// </summary>
        /// <returns></returns>
        public int Updata(MemberModel member)
        {
            try
            {
                return Bll.Updata(member);
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }

        [HttpGet]
        /// <summary>
        /// 等级List
        /// </summary>
        /// <returns></returns>
        public List<LevelModel> LevelList()
        {
            return Bll.LevelList();
        }

        [HttpGet]
        //
        public IActionResult Memebrlist(int? id, string? name, int? levelId)
        {
            try
            {
                var list = Bll.Memebrlist(id,name,levelId);
                return Ok(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPost]
        /// <summary>
        /// 权益添加
        /// </summary>
        /// <returns></returns>
        public IActionResult RightAdd(RightModel right)
        {
            var Right = Bll.RightAdd(right);
            return Ok(Right);
        }

        /// <summary>
        /// 权益List
        /// </summary>
        /// <param name="totalConut"></param>
        /// <param name="topage"></param>
        /// <param name="name"></param>
        /// <param name="CTime"></param>
        /// <param name="ETime"></param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult RightList(string? name, DateTime? CTime, DateTime? ETime, int index = 1, int size = 3)
        {
            int totalConut = 0;
            int topage = 0;
            var list = Bll.RightList(out totalConut, out topage, name, CTime, ETime, index, size);
            return Ok(new {list = list, totalConut = totalConut, topage = topage });
        }

        [HttpPut]
        //修改会员权益状态
        public IActionResult UpdateRightstate(int id, int state)
        {
            try
            {
                var res = Bll.UpdateRightstate(id, state);
                return Ok(res);
            }
            catch (Exception)
            {
                throw;
            }                
        }


    }
}
